package com.gitee.ice1938.module.admin.framwork.core;

import java.io.Serializable;

/**
 * 操作类
 * 
 * @author ice1938@qq.com at 2019-5-31 15:54:27
 *
 */
public class Operation implements Serializable, Comparable<Operation> {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 8761324158998975940L;

	private String id;
	private String parentId;
	private String uri;
	private String iconClass = "fa fa-circle-o";
	private String title;
	private int position = 0;
	private String capability;
	private int type_ = -2;

	/**
	 * 类型 : -1：页面,0：目录 1：菜单 2：按钮
	 * 
	 * @author Administrator
	 *
	 */
	public enum Type {
		 dir(0), menu(1),page(2), button(3);
		private int value;

		private Type(int value) {
			this.value = value;
		}

		public int value() {
			return value;
		}
	}

	public String getTypeName() {
		for (Type element : Type.values()) {
	        if(this.type_== element.value){
	        	return element.name();
	        }
        }
		return "";
	}
	// //
	public String getText() {
		return title;
	}

	// //
	@Override
	public int compareTo(Operation o) {
		if (this.equals(o)) {
			return 0;
		} else if (o != null) {
			if (parentId != null && o.getParentId() != null) {
				if (parentId.equalsIgnoreCase(o.getParentId())) {
					if (position <= o.getPosition()) {
						return -1;
					} else {
						return 1;
					}
				} else {
					return parentId.compareToIgnoreCase(o.getParentId());
				}
			} else {
				if (position <= o.getPosition()) {
					return -1;
				} else {
					return 1;
				}
			}
		} else {
			return -1;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Operation other = (Operation) obj;
		if (capability == null) {
			if (other.capability != null)
				return false;
		} else if (!capability.equals(other.capability))
			return false;
		if (iconClass == null) {
			if (other.iconClass != null)
				return false;
		} else if (!iconClass.equals(other.iconClass))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (parentId == null) {
			if (other.parentId != null)
				return false;
		} else if (!parentId.equals(other.parentId))
			return false;
		if (position != other.position)
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		if (uri == null) {
			if (other.uri != null)
				return false;
		} else if (!uri.equals(other.uri))
			return false;
		return true;
	}

	public String getCapability() {
		return capability;
	}

	public String getIconClass() {
		return iconClass;
	}

	public String getId() {
		return id;
	}

	public String getParentId() {
		return parentId;
	}

	public int getPosition() {
		return position;
	}

	public String getTitle() {
		return title;
	}

	public String getUri() {
		return uri;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((capability == null) ? 0 : capability.hashCode());
		result = prime * result + ((iconClass == null) ? 0 : iconClass.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((parentId == null) ? 0 : parentId.hashCode());
		result = prime * result + position;
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		result = prime * result + ((uri == null) ? 0 : uri.hashCode());
		return result;
	}

	public Operation setCapability(String capability) {
		this.capability = capability;
		return this;
	}

	public Operation setIconClass(String iconClass) {
		this.iconClass = iconClass;
		return this;
	}

	public Operation setId(String id) {
		this.id = id;
		return this;
	}

	public Operation setParentId(String parentId) {
		this.parentId = parentId;
		return this;
	}

	public Operation setPosition(int position) {
		this.position = position;
		return this;
	}

	public Operation setTitle(String title) {
		this.title = title;
		return this;
	}

	public Operation setUri(String uri) {
		this.uri = uri;
		return this;
	}

	@Override
	public String toString() {
		return "Operation [id=" + id + ", parentId=" + parentId + ", uri=" + uri + ", iconClass=" + iconClass
		        + ", title=" + title + ", position=" + position + ", capability=" + capability + ", type_=" + type_ + "]";
	}

	public int getType() {
		return type_;
	}

	public void setType_(int type) {
		this.type_ = type;
	}

}
